package com.itheima.jobs;

import com.itheima.dao.OrderSettingDao;
import com.itheima.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;

/**
 * Created with IntelliJ IDEA.
 * Author: Vergil
 * Date: 2019/8/29
 * Description:定时清理预约设置历史数据类
 */
public class ClearResvJob {
    @Autowired
    private OrderSettingDao orderSettingDao;

    public void clearReserv() throws Exception {

        Calendar calendar = Calendar.getInstance();
        //安全起见,选择清理5月之前的数据,可在下行随时根据情况调整
        calendar.add(Calendar.MONTH,-5 );
        String date = DateUtils.parseDate2String(calendar.getTime());
        System.out.println("date = " + date);
        try {
            orderSettingDao.deleteByDate(date);
            System.out.println("deleted successfully");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
